﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
using LitJson;

namespace tcp_SocketServer
{
    class Program
    {
        static void Main(string[] args)
        {

            Socket tcp_ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            IPAddress ipaddress = new IPAddress(new byte[] { 192, 168, 2, 82 });

            EndPoint local_EndPoint = new IPEndPoint(ipaddress, 7788);

            tcp_ServerSocket.Bind(local_EndPoint);

            Console.WriteLine("=绑定ip成功=");

            tcp_ServerSocket.Listen(100);

            Console.WriteLine("=监听成功=");

            byte[] data = new byte[1024];

            Socket tcp_ClientSocket = tcp_ServerSocket.Accept();

            int leng =  tcp_ClientSocket.Receive(data);

            JSONNode jn = JSON.Parse(Encoding.UTF8.GetString(data,0,leng));

            Console.WriteLine("=====接受客户端数据======" + jn["info"]["age"]);

            JSONClass jc = new JSONClass();

            jc["aabc"] = "请告诉我35434534你是谁？"; 

            string aabc = jc.ToString();

            byte[] data2 = new byte[1024];

            data2 = Encoding.UTF8.GetBytes(aabc);

            tcp_ClientSocket.Send(data2);

            Console.ReadKey();
        }
    }
}
